<?php
class p_new extends page_controllor 
{
    public function __construct($get_param)
    {
        parent::__construct($get_param);
    }
    
    public function run ()
    {
        $this->set_page_title('最新商品');
        $page = (int)$this->get_input(0);
        $page = $page < 1 ? 1 : $page;
        
        $oArraytree = new lib_arraytree(array());
        $oArraytree->restart(k::config('product_class'));
        $namefield = $this->__isLangEng ? 'eng_name' : 'name';
        $aProductClass = $oArraytree->get_id2field( $namefield );
        
        $total = 0;
        $oProduct = K::load_mod('product');
        $oProduct->list_date($total , $page , 7) or $this->busy();
            $aTmpDate = $oProduct->get_data();
            foreach ($aTmpDate as $a)
                $aDate[] = $a['cdate'];
            
        $oProduct->list_by_date($aDate);
        $aProduct = $oProduct->get_data();
        $aDate2Product = array();
        if(count($aProduct) > 0)
        {
            foreach ($aProduct as $k => $row)
            {
                $row['name'] = $this->__isLangEng ? K_str::un_html($row['eng_name']) : K_str::un_html($row['name']);
                $row['cover_url'] = product2coverpath($row['id'] , true);
                $row['product_url'] = '/product/show/'.$row['sn'];
                
                $aDate2Product[$row['cdate']][] = $row;
            }
            krsort($aDate2Product);
        }
        
        
        $out_data = array(
            'products' => $aDate2Product,
            'product_class' => $aProductClass,
            'total' => $total,
            'page' => $page
        );
        $this->set_page_title($this->__lang['gTitle_p_newProduct'].'_'.$this->__lang['gTitle_page_title']);
        $this->output('productnew' , $out_data);
    }
}
?>